package com.consumer;

import com.constant.AuthConstant;
import com.constant.TopicConstant;
import com.pool.TreadPoolUtils;
import com.utils.RedisClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class RedisCacheConsumer {

    @Autowired
    private RedisClient redisClient;

    @KafkaListener(topics = TopicConstant.MAIN_CACHE_TOPIC, groupId = "maintenanceMan_group")
    public void consumeMaintenanceMan(ConsumerRecord<String, String> record) {
        TreadPoolUtils.getTokenConsumerPool().execute(() -> {
            String key = record.key();
            String jsonMaintenanceMan = record.value();

            redisClient.setString(AuthConstant.MAINTENANCEMAN_INFO_KEY + key, jsonMaintenanceMan, 4L);
            log.info("缓存写入成功key:{}",key);
        });
    }

    @KafkaListener(topics = TopicConstant.ADMIN_CACHE_TOPIC, groupId = "admin_group")
    public void consumeAdmin(ConsumerRecord<String, String> record) {
        TreadPoolUtils.getTokenConsumerPool().execute(() -> {
            String key = record.key();
            String jsonAdmin = record.value();

            redisClient.setString(AuthConstant.ADMIN_INFO_KEY + key, jsonAdmin, 4L);
            log.info("缓存写入成功key:{}",key);
        });
    }





}
